package com.android.geotrack;

import java.util.LinkedList;

import com.android.geotrack.user.LoadUsersRunnable;


import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.GridView;

public class TrackActivity extends Activity
{
	private GridView gridview;
	private ProgressDialog pd;
	private Thread loadUsers;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.track);
		gridview = (GridView) findViewById(R.id.usergrid);
		loadUsers = new Thread(new LoadUsersRunnable(GeoTrack.currentUser, this));
		Log.v("Activity creation", "TrackActivity");
	}
	
	@Override
	protected void onResume()
	{
		super.onResume();
		if(!LoadUsersRunnable.lur_started) {
			loadUsers = new Thread(new LoadUsersRunnable(GeoTrack.currentUser, this));
			pd = ProgressDialog.show(this, "Working..", "Loading nearby user profiles!", true, false);
			loadUsers.start();
		}
	}
		
	public Handler messageHandler = new Handler() 
		{
			@Override
			public void handleMessage(Message msg)
			{
				pd.dismiss();
				
				switch(msg.what) {
				case 1337:
					Object[] result = (Object[]) msg.obj;
					TrackActivity.this.gridview.setAdapter(new TrackAdapter(TrackActivity.this, result[0], result[1]));
					break;
				}
			}
		};

}